package it.unibo.android.convoycruisecontrol.chiefboatsubsystem;

import it.unibo.convoycruisecontrol.chiefboatsubsystem.ControlPanel;
import it.unibo.convoycruisecontrol.chiefboatsubsystem.IControlPanel;
import it.unibo.convoycruisecontrol.progettodesignandroid.R;
import it.unibo.convoycruisecontrol.progettodesignandroid.R.id;
import it.unibo.convoycruisecontrol.progettodesignandroid.R.layout;
import it.unibo.util.measures.KilometersSecondToMetersSecond;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class ControlPanelController extends LinearLayout{

	private IControlPanel model= null;
	private Button startButton = null;
	private Button stopButton = null;
	private Button sendButton = null;
	private EditText expressionEditText = null;
	
	public ControlPanelController(Activity activity, IControlPanel controlPanel) {
		super(activity, null);
		
		this.model = controlPanel;
	    
		LayoutInflater layoutInflater = 
	              (LayoutInflater)activity.getSystemService   
	                      (Context.LAYOUT_INFLATER_SERVICE);
	    View view = layoutInflater.inflate(R.layout.controlpanel, this);
	 
	    startButton = (Button) view.findViewById(R.id.start);
	    startButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				model.startConvoy();
				//Log.d("MY CONSOLE", "START");
			}
		});
	    
	    stopButton = (Button) view.findViewById(R.id.stop);
	    stopButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				model.stopConvoy();
			}
		});
	    
	    sendButton = (Button) view.findViewById(R.id.send);
	    sendButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				expressionEditText = (EditText) findViewById(R.id.expression);
				model.setSpeed((float) KilometersSecondToMetersSecond.convert(Float.parseFloat(expressionEditText.getText().toString())));

//				Log.d("MY CONSOLE", "SEND" + expressionEditText.getText().toString());
			}
		});
	}
}
